package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wangqi
 * @date 2024/1/4 11:04
 */
@Slf4j
@RestController("userOrderController")
@RequestMapping("/user")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/order/submit")
    public Result<OrderSubmitVO> submitOrders(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单：{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = ordersService.submitOrders(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    //历史订单
    @GetMapping("/order/historyOrders")
    public Result<PageResult> historyOrders(Integer page, Integer pageSize, Integer status){
        log.info("查询历史订单：page={},pageSize={},status={}",page,pageSize,status);
        PageResult pageResult = ordersService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    @GetMapping("/order/orderDetail/{id}")
    public Result<OrderVO> findOrderVOById(@PathVariable Long id){
        log.info("根据订单id获取订单详情：id={}",id);
        OrderVO orderVO = ordersService.findOrdersById(id);
        return Result.success(orderVO);
    }

    @PutMapping("/order/cancel/{id}")
    public Result cancel(@PathVariable Long id){
        log.info("取消订单：id={}",id);
        ordersService.cancel(id);
        return Result.success();
    }
}
